package com.qiyebox.web.controller.biz;

import com.qiyebox.common.annotation.Log;
import com.qiyebox.common.core.controller.BaseController;
import com.qiyebox.common.core.domain.AjaxResult;
import com.qiyebox.common.core.page.TableDataInfo;
import com.qiyebox.common.enums.BusinessType;
import com.qiyebox.common.utils.http.OCRUtils;
import com.qiyebox.common.utils.poi.ExcelUtil;
import com.qiyebox.system.domain.ShotScreen;
import com.qiyebox.system.service.IShotScreenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author qiyebox
 * @date 2025-01-17
 */
@Controller
@RequestMapping("/system/screen")
@Api("截图管理接口")
public class ShotScreenController extends BaseController {
    private String prefix = "system/screen";

    @Autowired
    private IShotScreenService shotScreenService;

    //    @RequiresPermissions("system:screen:view")
    @GetMapping()
    public String screen() {
        return prefix + "/screen";
    }

    /**
     * 查询【请填写功能名称】列表
     */
//    @RequiresPermissions("system:screen:list")
    @PostMapping("/list")
    @ApiOperation("截图列表接口")
    @ResponseBody
    public TableDataInfo list(ShotScreen shotScreen) {
        startPage();
        List<ShotScreen> list = shotScreenService.selectShotScreenList(shotScreen);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
//    @RequiresPermissions("system:screen:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShotScreen shotScreen) {
        List<ShotScreen> list = shotScreenService.selectShotScreenList(shotScreen);
        ExcelUtil<ShotScreen> util = new ExcelUtil<ShotScreen>(ShotScreen.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
//    @RequiresPermissions("system:screen:add")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
//    @RequiresPermissions("system:screen:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("截图新增接口")
    @ResponseBody
    public AjaxResult addSave(ShotScreen shotScreen) {
        return toAjax(shotScreenService.insertShotScreen(shotScreen));
    }

    @PostMapping("/batch_add")
    @ApiOperation("截图批量新增接口")
    @ResponseBody
    public AjaxResult batchAdd(@RequestBody List<ShotScreen> shotScreen) {
        return toAjax(shotScreenService.insertBatchShotScreen(shotScreen));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @RequiresPermissions("system:screen:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        ShotScreen shotScreen = shotScreenService.selectShotScreenById(id);
        mmap.put("shotScreen", shotScreen);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
//    @RequiresPermissions("system:screen:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ApiOperation("截图修改接口")
    @ResponseBody
    public AjaxResult editSave(ShotScreen shotScreen) {
        return toAjax(shotScreenService.updateShotScreen(shotScreen));
    }

    /**
     * 删除【请填写功能名称】
     */
//    @RequiresPermissions("system:screen:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ApiOperation("截图删除接口")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(shotScreenService.deleteShotScreenByIds(ids));
    }


    /**
     * 分析图片
     */
    @Log(title = "分析图片", businessType = BusinessType.INSERT)
    @PostMapping("/imgAnalysis")
    @ResponseBody
    public AjaxResult imgAnalysis(String image_url) {
        try {
            return AjaxResult.success(OCRUtils.parseRes(image_url));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }


    /**
     * 转换文字内容
     */
    @Log(title = "转换文字内容", businessType = BusinessType.INSERT)
    @PostMapping("/translation")
    @ResponseBody
    public AjaxResult translation(String content) {
        try {
            return AjaxResult.success(OCRUtils.translationTools(content));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }
}
